<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<!-- HTML file produced from file: manual.tex --
 -- using Hyperlatex v 2.3.1 (c) Otfried Cheong--
 -- on Emacs 21.4 (patch 12) "Portable Code" XEmacs Lucid, Wed Jun  2 18:56:55 2004 -->
<HEAD>
<TITLE>Scheme 48 Manual -- Interfaces</TITLE>

</HEAD><BODY BGCOLOR="#ffffff">
<EM>Scheme 48 Manual</EM> | <A HREF="s48manual.html#top_node">Contents</A> | In Chapter: <A HREF="s48manual_24.html">Module system</A><BR>Previous: <A HREF="s48manual_26.html">The configuration language</A> | Next: <A HREF="s48manual_28.html">Macros</A>
<H2>Interfaces</H2>
<CODE>define-interface</CODE>
<P>An interface can be thought of as the type of a structure.  In its
basic form it is just a list of variable names, written <TT>(export
<CODE><I>name</I></CODE> ...)</TT>.  However, in place of
a name one may write <TT>(<CODE><I>name</I></CODE> <CODE><I>type</I></CODE>)</TT>, indicating the type
of <CODE><I>name</I></CODE>'s binding.
The type field is optional, except
 that exported macros must be indicated with type <TT>:syntax</TT>.
<P>Interfaces may be either anonymous, as in the example in the
introduction, or they may be given names by a <TT>define-interface</TT>
form, for example
<BLOCKQUOTE><PRE>
(define-interface foo-interface (export a c cons))
(define-structure foo foo-interface ...)
</PRE></BLOCKQUOTE>
In principle, interfaces needn't ever be named.  If an interface
had to be given at the point of a structure's use as well as at the
point of its definition, it would be important to name interfaces in
order to avoid having to write them out twice, with risk of mismatch
should the interface ever change.  But they don't.
<P>Still, there are several reasons to use <TT>define-interface</TT>:
<OL><LI>It is important to separate the interface definition from the
package definitions when there are multiple distinct structures that
have the same interface -- that is, multiple implementations of the
same abstraction.
<P><LI>It is conceptually cleaner, and often useful for documentation
purposes, to separate a module's specification (interface) from its
implementation (package).
<P><LI>Our experience is that configurations that are separated into
interface definitions and package definitions are easier to read; the
long lists of exported bindings just get in the way most of the time.
</OL>
<P>The <A NAME="1">&nbsp;</A><CODE>compound-interface</CODE> operator forms an interface that is the
union of two or more component interfaces.  For example,
<BLOCKQUOTE><PRE>
(define-interface bar-interface
  (compound-interface foo-interface (export mumble)))
</PRE></BLOCKQUOTE>
defines <TT>bar-interface</TT> to be <TT>foo-interface</TT> with the name
<TT>mumble</TT> added.
<P><P>
  
Previous: <A HREF="s48manual_26.html">The configuration language</A> | Next: <A HREF="s48manual_28.html">Macros</A></BODY></HTML>
